<!DOCTYPE html>
<html lang="en">

<head>

    <!-- Basic -->
    <meta charset="UTF-8"/>

    <title>询价管理</title>

    <!-- Mobile Metas -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>

    <!-- Favicon and touch icons -->
    <link rel="shortcut icon" href="__ADMIN__/assets/ico/favicon.ico" type="image/x-icon"/>
    <link rel="apple-touch-icon" href="__ADMIN__/assets/ico/apple-touch-icon.png"/>
    <link rel="apple-touch-icon" sizes="57x57" href="__ADMIN__/assets/ico/apple-touch-icon-57x57.png"/>
    <link rel="apple-touch-icon" sizes="72x72" href="__ADMIN__/assets/ico/apple-touch-icon-72x72.png"/>
    <link rel="apple-touch-icon" sizes="76x76" href="__ADMIN__/assets/ico/apple-touch-icon-76x76.png"/>
    <link rel="apple-touch-icon" sizes="114x114" href="__ADMIN__/assets/ico/apple-touch-icon-114x114.png"/>
    <link rel="apple-touch-icon" sizes="120x120" href="__ADMIN__/assets/ico/apple-touch-icon-120x120.png"/>
    <link rel="apple-touch-icon" sizes="144x144" href="__ADMIN__/assets/ico/apple-touch-icon-144x144.png"/>
    <link rel="apple-touch-icon" sizes="152x152" href="__ADMIN__/assets/ico/apple-touch-icon-152x152.png"/>

    <!-- start: CSS file-->

    <!-- Vendor CSS-->
    <link href="__ADMIN__/assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="__ADMIN__/assets/vendor/skycons/css/skycons.css" rel="stylesheet"/>
    <link href="__ADMIN__/assets/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>

    <!-- Plugins CSS-->
    <link href="__ADMIN__/assets/css/toastr.min.css" rel="stylesheet"/>
    <link href="__ADMIN__/assets/plugins/bootkit/css/bootkit.css" rel="stylesheet"/>
    <link href="__ADMIN__/assets/plugins/fullcalendar/css/fullcalendar.css" rel="stylesheet"/>
    <link href="__ADMIN__/assets/plugins/jquery-ui/css/jquery-ui-1.10.4.min.css" rel="stylesheet"/>

    <!-- Theme CSS -->
    <link href="__ADMIN__/assets/css/jquery.mmenu.css" rel="stylesheet"/>

    <!-- Page CSS -->
    <link href="__ADMIN__/assets/css/style.css" rel="stylesheet"/>
    <link href="__ADMIN__/assets/css/add-ons.min.css" rel="stylesheet"/>

    <!-- end: CSS file-->

    <!-- Head Libs -->
    <script src="__ADMIN__/assets/plugins/modernizr/js/modernizr.js"></script>

</head>

<body>

<!-- Start: Header -->
{include file="public/header"}
<!-- End: Header -->

<!-- Start: Content -->
<div class="container-fluid content">
    <div class="row">

        <!-- Sidebar -->
        {include file="public/sidebar"}
        <!-- End Sidebar -->

        <!-- Main Page -->
        <div class="main sidebar-minified">

            <!-- Page Header -->
            <div class="page-header">
                <div class="pull-left">
                    <ol class="breadcrumb visible-sm visible-md visible-lg">
                        <li><a href="{:url('/index')}"><i class="icon fa fa-home"></i>后台首页</a></li>
                    </ol>
                </div>
                <div class="pull-right">
                    <h2>询价管理</h2>
                </div>
            </div>
            <!-- End Page Header -->

            <!--详细信息模态框-->
            <div class="modal fade" id="detailModal" style="margin-top: 70px;" tabindex="-1" role="dialog"
                 aria-labelledby="myModalLabel">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="row">
                            <div class="col-md-12"
                                 style="float: none; display: block; margin-left: auto; margin-right: auto;">
                                <div class="panel-heading bk-bg-primary">
                                    <h6 id="detailTitle"></h6>
                                </div>
                                <div class="panel-body">
                                    <form class="form-horizontal" style="text-align: center;">

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">ID</label>
                                            <div class="col-md-9">
                                                <p id="detail-id" class="form-control-static"></p>
                                            </div>
                                        </div>
                                        <hr>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">询价期权ID</label>
                                            <div class="col-md-9">
                                                <p id="detail-reper_id" class="form-control-static"></p>
                                            </div>
                                        </div>
                                        <hr>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">询价期权名称</label>
                                            <div class="col-md-9">
                                                <p id="detail-reper_name" class="form-control-static"></p>
                                            </div>
                                        </div>
                                        <hr>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">询价时间</label>
                                            <div class="col-md-9">
                                                <p id="detail-ask_time" class="form-control-static"></p>
                                            </div>
                                        </div>
                                        <hr>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">询价用户ID</label>
                                            <div class="col-md-9">
                                                <p id="detail-user_id" class="form-control-static"></p>
                                            </div>
                                        </div>
                                        <hr>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">询价用户名</label>
                                            <div class="col-md-9">
                                                <p id="detail-user_name" class="form-control-static"></p>
                                            </div>
                                        </div>
                                        <hr>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">名义本金</label>
                                            <div class="col-md-9">
                                                <p id="detail-capital_money" class="form-control-static"></p>
                                            </div>
                                        </div>
                                        <hr>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">回执状态</label>
                                            <div class="col-md-9">
                                                <p id="detail-status" class="form-control-static"></p>
                                            </div>
                                        </div>
                                        <hr>

                                    </form>
                                    <br>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--End 相信信息模态框-->

            <!--回执模态框-->
            <div class="modal fade" id="answerModal" style="margin-top: 70px;" tabindex="-1" role="dialog"
                 aria-labelledby="myModalLabel">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="row">
                            <div class="col-md-12"
                                 style="float: none; display: block; margin-left: auto; margin-right: auto;">
                                <div class="panel-heading bk-bg-primary">
                                    <h6 id="answerTitle"></h6>
                                </div>
                                <div class="panel-body">

                                    <form id="answerForm" action="" method="post" class="form-horizontal">

                                        <input type="hidden" name="_method" value="put">
                                        <input id="reper_id" type="hidden" name="reper_id" value="">

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">回执期权名称</label>
                                            <div class="col-md-9">
                                                <p id="answerOptionName" class="form-control-static"></p>
                                            </div>
                                        </div>

                                        <div class="form-group" id="beforeAnswerMonth">
                                            <label class="col-md-3 control-label">回执用户名称</label>
                                            <div class="col-md-9">
                                                <p id="answerUserName" class="form-control-static"></p>
                                            </div>
                                        </div>

                                        <br>
                                        <div class="form-group" style="text-align: center;">
                                            <button type="submit" class="bk-margin-5 btn btn-default"> 确认回执</button>
                                        </div>
                                    </form>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--End 回执模态框-->

            <!--询价列表-->
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel">
                        <div class="panel-heading bk-bg-primary">
                            <h6><i class="fa fa-money red"></i><span class="break"></span>询价列表</h6>
                            <div class="panel-actions">
                                <a href="javascript:void(0)" data-target="#addModal" data-toggle="modal"><i
                                        class="fa fa-plus"></i></a>
                            </div>
                        </div>
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered bootstrap-datatable datatable">
                                    <thead>
                                    <tr>
                                        <th style="text-align: center">ID</th>
                                        <th style="text-align: center">询价期权名称</th>
                                        <th style="text-align: center">询价用户</th>
                                        <th style="text-align: center">状态</th>
                                        <th style="text-align: center">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    {volist name="inquiries" id="inquiry"}
                                    <tr>
                                        <td style="text-align: center; vertical-align: middle;display: table-cell;">
                                            {$inquiry.id}
                                        </td>
                                        <td style="text-align: center; vertical-align: middle;display: table-cell;">
                                            {$inquiry.reper_name}
                                        </td>
                                        <td style="text-align: center; vertical-align: middle;display: table-cell;">
                                            {$inquiry.user_name}
                                        </td>
                                        <td style="text-align: center; vertical-align: middle;display: table-cell;">
                                            {if condition="$inquiry.status eq 1"}
                                            <span class="label label-warning">待回执</span>
                                            {else /}
                                            <span class="label label-success">已回执</span>
                                            {/if}
                                        </td>
                                        <td style="text-align: center; vertical-align: middle;display: table-cell;">

                                            <button type="button" class="bk-margin-5 btn btn-success detail-btn"
                                                    data-target="#detailModal" data-toggle="modal"
                                                    data-id="{$inquiry['id']}">
                                                <i class="fa fa-search-plus"></i>
                                            </button>

                                            <button type="button" class="bk-margin-5 btn btn-info answer-btn"
                                                    data-target="#answerModal" data-toggle="modal"
                                                    data-id="{$inquiry.id}"
                                                    {if condition="$inquiry.status eq 2"}
                                                    disabled
                                                    {/if}
                                                    >
                                                <i class="fa fa-check"></i>
                                            </button>

                                        </td>
                                    </tr>
                                    {/volist}
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="list-page" style="text-align: center"></div>
                    </div>
                </div>
            </div>
            <!--End 询价列表-->

        </div>
        <!-- End Main Page -->

    </div>
</div><!--/container-->

<div class="clearfix"></div>


<!-- start: JavaScript-->

<!-- Vendor JS-->
<script src="__ADMIN__/assets/vendor/js/jquery.min.js"></script>
<script src="__ADMIN__/assets/vendor/js/jquery-2.1.1.min.js"></script>
<script src="__ADMIN__/assets/vendor/js/jquery-migrate-1.2.1.min.js"></script>
<script src="__ADMIN__/assets/vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="__ADMIN__/assets/vendor/skycons/js/skycons.js"></script>

<!-- Plugins JS-->
<script src="__ADMIN__/assets/js/toastr.min.js"></script>
<script src="__ADMIN__/assets/plugins/jquery-ui/js/jquery-ui-1.10.4.min.js"></script>
<script src="__ADMIN__/assets/plugins/moment/js/moment.min.js"></script>
<script src="__ADMIN__/assets/plugins/fullcalendar/js/fullcalendar.min.js"></script>

<!-- Theme JS -->
<script src="__ADMIN__/assets/js/jquery.mmenu.min.js"></script>
<script src="__ADMIN__/assets/js/core.min.js"></script>

<!-- Pages JS -->
<script src="__ADMIN__/assets/js/pages/table.js"></script>

<!-- end: JavaScript-->

<script type="text/javascript">

    // 设置弹框参数
    toastr.options = {
        closeButton: true,//是否显示关闭按钮
        progressBar: true,//实现显示计时条
        timeOut: "3000",//自动关闭时间
        positionClass: "toast-top-full-width" // 顶端，宽度铺满整个屏幕
    };

    // 点击了详情按钮
    $('button.detail-btn').each(function () {
        $(this).click(function () {
            ajaxRead($(this).attr('data-id'));
        })
    });

    // 点击了回执按钮
    $('button.answer-btn').each(function () {
        $(this).click(function () {
            ajaxAnswer($(this).attr('data-id'));
        })
    });

    // 点击了删除按钮
    $('button.del-btn').each(function () {
        $(this).click(function () {

            if (confirm('你确定要 [删除] 吗?')) {
                // 删除table的tr
                var obj = $(this).parents('tr');

                ajaxDel($(this).attr('data-id'), obj);
            }

        })
    });

    // ajax获取指定需要显示的询价的信息
    function ajaxRead(id) {
        $.ajax({
            type: 'get',
            data: {'id': id},
            url: '{:url("/inquiry/' + id + '")}',
            dataType: 'json',
            success: function (inquiryInfo) {

                // 显示
                $('#detail-id').html(inquiryInfo.id);
                $('#detail-reper_id').html(inquiryInfo.reper_id);
                $('#detail-reper_name').html(inquiryInfo.reper_name);
                $('#detail-ask_time').html(inquiryInfo.ask_time);
                $('#detail-user_id').html(inquiryInfo.user_id);
                $('#detail-user_name').html(inquiryInfo.user_name);
                $('#detail-capital_money').html(inquiryInfo.capital_money);
                if (inquiryInfo.status == 1) {
                    $('#detail-status').html('待回执');
                } else {
                    // 回执价格
                    var str = '一个月 : ' + inquiryInfo.oneMonth + '<br> 两个月 : ' + inquiryInfo.twoMonth + '<br> 三个月 : ' + inquiryInfo.threeMonth;
                    $('#detail-status').html(str);
                }

                $('#detailTitle').html('正在查看 【' + inquiryInfo.user_name + ' 对 ' + inquiryInfo.reper_name + '】 的询价详细信息')
            }
        });
    }

    // ajax执行回执
    function ajaxAnswer(id) {

        // ajax查询需要回执的月份
        $.ajax({
            type: 'get',
            data: {'id': id},
            url: '{:url("/inquiry/' + id + '")}',
            dataType: 'json',
            success: function (inquiryInfo) {

                $('div').remove('.appendMonth');

                // 拼接需要回执的月
                var answerMonthStr = '';
                if (inquiryInfo.oneMonth !== null) {
                    answerMonthStr += appendAnswerMonthStr('一个月', 'oneMonth');
                }
                if(inquiryInfo.twoMonth !== null) {
                    answerMonthStr += appendAnswerMonthStr('两个月', 'twoMonth');
                }
                if(inquiryInfo.threeMonth !== null) {
                    answerMonthStr += appendAnswerMonthStr('三个月', 'threeMonth');
                }

                $('#beforeAnswerMonth').after(answerMonthStr);

            }
        });


        $.ajax({
            type: 'get',
            data: {'id': id},
            url: '{:url("inquiry/' + id + '/edit")}',
            dataType: 'json',
            success: function (inquiryInfo) {

                // 显示
                $('#answerOptionName').html(inquiryInfo.reper_name);
                $('#answerUserName').html(inquiryInfo.username);
                $('#reper_id').val(inquiryInfo.reper_id);
                $('#answerTitle').html('正在回执 【 ' + inquiryInfo.username + ' 对 ' + inquiryInfo.reper_name + ' 】 的询价');

                // 修改answerForm的action
                $('form#answerForm').attr('action', '/inquiry/' + id);

            }
        });
    }

    // ajax删除指定的用户
    function ajaxDel(id, obj) {
        $.ajax({
            type: 'delete',
            data: {'id': id},
            url: '{:url("/inquiry/' + id + '")}',
            success: function (result) {
                console.log(result);
                if (result == 1) {
                    toastr.success('删除用户成功!');
                    obj.remove();
                    history.go(-1);
                } else {
                    toastr.error('删除用户失败!');
                }
            }
        });
    }

    function appendAnswerMonthStr(monthName, inputName) {
        var str =
`<div class="form-group appendMonth">
    <label class="col-md-3 control-label">${monthName}</label>
    <div class="col-md-9">
        <input type="text" name="${inputName}" class="form-control">
        <span class="help-block"></span>
    </div>
</div>`;
          return str;
    }

</script>

</body>

</html>